package com.zjg.service;

import java.io.InputStream;
import java.util.List;

import com.zjg.bean.User;
import com.zjg.dao.RegisterDaoImp;
import com.zjg.dao.UserDaoImp;
import com.zjg.dao.iface.RegisterDao;
import com.zjg.dao.iface.UserDao;
import com.zjg.service.iface.UserService;

public class UserServiceImp implements UserService {
	UserDao userdao=new UserDaoImp();
	RegisterDao rd=new RegisterDaoImp();
	@Override
	public boolean Login(String name, String password) {
		boolean flag=false;
		if(userdao.checkUser(name, password)==1) {
			flag=true;
		}
		return flag;
	}
	@Override
	public User setUserHobby(User user) {
		
		return userdao.getUserHobby(user);
		
	}
	@Override
	public List<User> getUserMessage() {
		
		return userdao.getUserMessage();
	}
	@Override
	public boolean deleteUsers(String ids) {
		boolean flag=false;
		if(userdao.deleteUser(ids)>0) {
		flag=true;	
		}
		return true;
	}
	@Override
	public boolean EditUser(User user) {
		boolean flag=false;
		String userid=String.valueOf(user.getId());
		if(deleteUsers(userid)) {
			if(rd.register(user,null)>1) {
				flag=true;
			}
		};
		return flag;
	}
	
	
	@Override
	public User getUser(String name) {
		User user=userdao.getUser(name);
		User user0=userdao.getAuthority(name);
		user.setRole(user0.getRole());
		user.setCode(user0.getCode());
		return user;
		
	}
//	public User getUser(String name) {
//		User user=userdao.getUser(name);
//		User user0=userdao.getAuthority(name);
//		
//		String[] authorname=new String[user0.getCode().length];
//		String[] authorcode=new String[user0.getCode().length];
//		for(int i=0;i<user0.getCode().length;i++) {
//			authorname[i]=user0.getRole()[i];
//			authorcode[i]=user0.getCode()[i];
//			System.out.println(user0.getRole()[i]);
//		}
//		user.setRole(authorname);
//		user.setCode(authorcode);
//		return user;
	@Override
	public boolean changestate(String name, String ip, String state) {
		boolean flag=false;
		if(userdao.onlinestate(name, ip, state)>0) {
			flag=true;
		};
		return flag;
	}
	@Override
	public InputStream getHeadIcon(int id) {
		
		return userdao.getHeadIcon(id);
	}
	@Override
	public User getUserById(int id) {
		
		return userdao.getUserById(id);
	}
	@Override
	public List<User> getFriendsById(int id) {
		
		return userdao.getFriend(id);
	}
	@Override
	public void addFriend(int id, int fid) {
		userdao.addFriend(id, fid);
		
	}
	
		

}
